package com.xsr.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @author 邢式瑞
 * @version 1.0
 * @project gp14Sm
 * @date 2022/9/7 17:52
 */
@Component
@Aspect
public class Advice {
    @Pointcut(value = "execution(* *..UserServiceImpl.*(..))")
    public  void pointCut(){}
    @Around(value = "pointCut()")
    public Object AroundAdvice(ProceedingJoinPoint proceedingJoinPoint){
        System.out.println("方法之前进入环绕");
        try {
            //执行核心代码
            Object result = proceedingJoinPoint.proceed();
//            MethodSignature signature = (MethodSignature) proceedingJoinPoint.getSignature();
//            Class returnType = signature.getReturnType();
//            Object o = returnType.newInstance();
//            String name = returnType.getName();
            System.out.println("后置代码");
            return result;
        } catch (Throwable throwable) {
            System.out.println("环绕通知异常:"+throwable.getMessage());
        }
        return null;
    }
}
